/*
   (C) 2007 - Michael Ocean - Boston University

  This work is a part of the larger snBench project.  Information
  can be found at: http://csr.bu.edu/snbench

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package sxe;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;

import stepide.STEPVisualizer.JStepPanel;

public class Gui {

    /* graphical debugging interface */
	private JStepPanel JDebugPanel;
	private step.Graph graph;
	private JTextPane jtext;
		
	public Gui(step.Graph g){
		/* graphical debugging interface */
		graph = g;
		JDebugPanel = new JStepPanel(graph); 
		JFrame frame = new JFrame("Debug STEP monitor");
		frame.setPreferredSize(new Dimension(800,600));
		JDebugPanel.setPreferredSize(new Dimension(800,500));
		jtext = new JTextPane();
		
		frame.add(new JSplitPane(JSplitPane.VERTICAL_SPLIT,JDebugPanel,new JScrollPane(jtext)));
		
		frame.pack();
		frame.setVisible(true);
	}
	

	public void refreshGraph(){
		JDebugPanel.RefreshFromGraph();
	}
	
	public void highlightNode(String sID){
		colorNode(sID,Color.YELLOW);
	}
	public void unhighlightNode(String sID){
		colorNode(sID,null);
	}
	
	private void colorNode(String sID, Color c){
		JDebugPanel.ColorNode(graph.GetNode(sID),c);
	}

	public void setText(String string) {
		jtext.setText(string);
	}

	public void appendText(String text) {
		synchronized(this){
			try {
				jtext.getDocument().insertString(
						0, //instance.jtext.getDocument().getLength(),
						text + "\n",
						null);
			} catch (BadLocationException e) {
				e.printStackTrace();
			}
		}
	}
}
